package com.zcb.rxjavapractice.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.zcb.rxjavapractice.R;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action;
import rx.functions.Action1;
import rx.functions.Func1;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        splash();
    }
    /**
     * time操作符
     * RxJAVA使用time操作符实现 定时效果。
     */
    private void splash(){
        ImageView view= (ImageView) findViewById(R.id.splashImg);
        view.setImageResource(R.drawable.welcome);
        Observable.timer(3, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
                .map(new Func1<Long, Object>() {
                    @Override
                    public Object call(Long aLong) {
//                        startActivity(new Intent(SplashActivity.this,Demo2Activity.class));
                        finish();
                        return null;
                    }
                }).subscribe();
    }














}
